package com.zhaopin.gitlab;

public class Test {
    public static void main(String[] args) {
        String s = "package function\n" +
                "\n" +
                "\n" +
                "import org.apache.commons.lang3.StringUtils\n" +
                "\n" +
                "import java.util.stream.Collectors\n" +
                "\n" +
                "/**\n" +
                " * 求职意向1拆3大库搜索需求\n" +
                " * @param obj\n" +
                " * @return\n" +
                " */\n" +
                "def runScript() {\n" +
                "    def input = ctx().input\n" +
                "    String id = input.get(\"userId\")\n" +
                "    String city = input.get(\"S_SOU_WORK_CITY\")\n" +
                "    String companyScale = input.get(\"S_SOU_COMPANY_SCALE\")\n" +
                "    String companyType = input.get(\"S_SOU_COMPANY_TYPE\")\n" +
                "    String eduLowestLevel = input.get(\"S_SOU_EDUCATION_LOWESTLEVEL\")\n" +
                "    String experience = input.get(\"S_SOU_WORK_EXPERIENCE\")\n" +
                "    String subwayLine = input.get(\"S_SOU_SUBWAY_LINE\")\n" +
                "    String subwayStation = input.get(\"S_SOU_SUBWAY_STATION\")\n" +
                "    String businessDistrict = input.get(\"S_SOU_BUSINESS_DISTRICT_NAME\")\n" +
                "    String salaryMin = input.get('S_SOU_SALARY_MIN_SINGLE')\n" +
                "    String salaryMax = input.get('S_SOU_SALARY_MAX_SINGLE')\n" +
                "\n" +
                "    // CVFILTER\n" +
                "    String cvFilter_eduLevel = input.get(\"CV_EDUCATION_LEVEL\")\n" +
                "    String cvFilter_birthYear = input.get(\"CV_BIRTH_YEAR\")\n" +
                "    String cvFilter_workYear = input.get(\"CV_WORK_YEAR\")\n" +
                "    String cvFilter_currentCity = input.get(\"CV_CURRENT_CITY\")\n" +
                "    String cvFilter_currentProvince = input.get(\"CV_CURRENT_PROVINCE\")\n" +
                "    String cvFilter_hukouCity = input.get(\"CV_HUKOU_CITY_ID\")\n" +
                "    String cvFilter_hukouProvince = input.get(\"CV_HUKOU_PROVINCE_ID\")\n" +
                "    String cvFilter_gender = input.get(\"CV_GENDER\")\n" +
                "    String cvFilter_maritalStatus = input.get(\"CV_MARITAL_STATUS\")\n" +
                "\n" +
                "    List<String> whereList = new ArrayList<>();\n" +
                "    whereList.add(\"u.user_id==\" + id);\n" +
                "    whereList.add(\"(p.ORG_VIP_LEVEL!=0 or p.JD_PAID_FLAG!=0)\");\n" +
                "    whereList.add(\"(p.Tag_Double_CompanyScore >= 0)\");\n" +
                "    whereList.add(\"(p.Tag_Int_DuplicatedSource==0)\");\n" +
                "    whereList.add(\"(p.SOU_POSITION_SOURCE_TYPE==1)\");\n" +
                "    whereList.add(\"(p.SOU_POSITION_TYPE==2)\");\n" +
                "    whereList.add(\"(p.SOU_APPLY_TYPE==1)\");\n" +
                "\n" +
                "    // CVFILTER\n" +
                "    if (StringUtils.isNotBlank(cvFilter_eduLevel)) {\n" +
                "        whereList.add(String.format(\"(p.SOU_EDUCATION_LEVEL CONTAINS ' %s ' AND p.JD_CVFILTER_MAX_DEGREE CONTAINS ' %s ')\", cvFilter_eduLevel, cvFilter_eduLevel));\n" +
                "    }\n" +
                "    if (StringUtils.isNotBlank(cvFilter_birthYear)) {\n" +
                "        whereList.add(String.format(\"(p.JD_CVFILTER_MIN_BORN_YEAR<=%s AND p.JD_CVFILTER_MAX_BORN_YEAR>=%s)\", cvFilter_birthYear, cvFilter_birthYear));\n" +
                "    }\n" +
                "    if (StringUtils.isNotBlank(cvFilter_workYear)) {\n" +
                "        whereList.add(String.format(\"(p.JD_CVFILTER_MIN_START_WORK_YEAR_MONTH<=%s AND p.JD_CVFILTER_MAX_START_WORK_YEAR_MONTH>=%s)\", cvFilter_workYear, cvFilter_workYear));\n" +
                "    }\n" +
                "    if (StringUtils.isNotBlank(cvFilter_currentCity)) {\n" +
                "        whereList.add(String.format(\"(p.JD_CVFILTER_CUR_LIVE_CITY==0 OR p.JD_CVFILTER_CUR_LIVE_CITY==%s)\", cvFilter_currentCity));\n" +
                "    }\n" +
                "    if (StringUtils.isNotBlank(cvFilter_currentProvince)) {\n" +
                "        whereList.add(String.format(\"(p.JD_CVFILTER_CUR_LIVE_PROVINCE==0 OR p.JD_CVFILTER_CUR_LIVE_PROVINCE==%s)\", cvFilter_currentProvince));\n" +
                "    }\n" +
                "    if (StringUtils.isNotBlank(cvFilter_hukouCity)) {\n" +
                "        whereList.add(String.format(\"(p.JD_CVFILTER_HUKOU_CITY==0 OR p.JD_CVFILTER_HUKOU_CITY==%s)\", cvFilter_hukouCity));\n" +
                "    }\n" +
                "    if (StringUtils.isNotBlank(cvFilter_hukouProvince)) {\n" +
                "        whereList.add(String.format(\"(p.JD_CVFILTER_HUKOU_PROVINCE==0 OR p.JD_CVFILTER_HUKOU_PROVINCE==%s)\", cvFilter_hukouProvince));\n" +
                "    }\n" +
                "    if (StringUtils.isNotBlank(cvFilter_gender)) {\n" +
                "        whereList.add(String.format(\"(p.JD_CVFILTER_GENDER==0 OR p.JD_CVFILTER_GENDER==%s)\", cvFilter_gender));\n" +
                "    }\n" +
                "    if (StringUtils.isNotBlank(cvFilter_maritalStatus)) {\n" +
                "        whereList.add(String.format(\"(p.JD_CVFILTER_MARRIAGE_STATUS==0 OR p.JD_CVFILTER_MARRIAGE_STATUS==%s)\", cvFilter_maritalStatus));\n" +
                "    }\n" +
                "\n" +
                "    // 地铁线\n" +
                "    if (StringUtils.isNotBlank(subwayLine)) {\n" +
                "        whereList.add(String.format(\"p.SOU_SUBWAY_LINE CONTAINS ' %s '\", subwayLine));\n" +
                "    }\n" +
                "    // 地铁站 多值\n" +
                "    if (StringUtils.isNotBlank(subwayStation)) {\n" +
                "        String subwayStationSplit = splitParam('SOU_SUBWAY_STATION CONTAINS',subwayStation,true)\n" +
                "        whereList.add(\"(\" + subwayStationSplit + \")\");\n" +
                "    }\n" +
                "    // city\n" +
                "    if (StringUtils.isNotBlank(city)) {\n" +
                "        whereList.add(String.format(\"p.SOU_WORK_CITY CONTAINS ' %s '\", city));\n" +
                "    }\n" +
                "    // salary\n" +
                "    if (StringUtils.isNotBlank(salaryMin) || StringUtils.isNotBlank(salaryMax)) {\n" +
                "        whereList.add(String.format(\"(p.SOU_SALARY_MAX>=\" + salaryMin + \" AND p.SOU_SALARY_MIN<=\" + salaryMax + \")\"))\n" +
                "    }\n" +
                "    // company scale\n" +
                "    if (StringUtils.isNotBlank(companyScale)) {\n" +
                "        String companyScaleSplit = splitParam('SOU_COMPANY_SCALE==',companyScale,false)\n" +
                "        whereList.add(\"(\" + companyScaleSplit + \")\");\n" +
                "    }\n" +
                "    // company type\n" +
                "    if (StringUtils.isNotBlank(companyType)) {\n" +
                "        String companyTypeSplit = splitParam('SOU_COMPANY_TYPE==',companyType,false)\n" +
                "        whereList.add(\"(\" + companyTypeSplit + \")\");\n" +
                "    }\n" +
                "    // edu lowest level\n" +
                "    if (StringUtils.isNotBlank(eduLowestLevel)) {\n" +
                "        String eduLowestLevelSplit = splitParam('SOU_EDUCATION_LOWESTLEVEL ==',eduLowestLevel,false)\n" +
                "        whereList.add(\"(\" + eduLowestLevelSplit + \")\");\n" +
                "    }\n" +
                "    // experience\n" +
                "    if (StringUtils.isNotBlank(experience)) {\n" +
                "        String experienceSplit = splitParam('SOU_WORK_EXPERIENCE==',experience,false)\n" +
                "        whereList.add(\"(\" + experienceSplit + \")\");\n" +
                "    }\n" +
                "    //商圈\n" +
                "    if (StringUtils.isNotBlank(businessDistrict)) {\n" +
                "        String businessSplit = splitParam('SOU_BUSINESS_DISTRICT_NAME CONTAINS',businessDistrict,true)\n" +
                "        whereList.add(\"(\" + businessSplit + \")\");\n" +
                "    }\n" +
                "    return String.format(\"use user_recommend; match (u:user_tag)-[e:hive_cf_path]-(p) where %s return p.SOU_POSITION_ID as positionId,p.SOU_COMPANY_AUTOID as orgId,p.JD_CREATE_STAFF_ID as staffId,e.position_score as position_score,p.SOU_POSITION_ID as USERID,e.position_score as score ORDER BY position_score DESC SKIP 0 LIMIT 1000;\", whereList.stream().collect(Collectors.joining(\" AND \")));\n" +
                "}\n" +
                "\n" +
                "static String splitParam(String param,String val,boolean quote) {\n" +
                "    String[] valArray = val.split(\";\");\n" +
                "    List<String> valList = new ArrayList();\n" +
                "    for(String i : valArray){\n" +
                "        if(quote){\n" +
                "            valList.add(String.format(\"p.%s ' %s '\",param,i));\n" +
                "        }else {\n" +
                "            valList.add(String.format(\"p.%s %s\",param,i));\n" +
                "        }\n" +
                "\n" +
                "    }\n" +
                "    String valString = valList.stream().collect(Collectors.joining(\" OR \"));\n" +
                "    return valString\n" +
                "}";
        String old = "    whereList.add(\"u.user_id==\" + id);";
        String newValue = "    whereList.add(\"id(u)==\" + \"'\"+id+\"'\");";
        System.out.println(s.contains(old));
        System.out.println(s.replace(old,newValue));
    }
}
